from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
import re

testCase = 'DBshopST034_余额调整'
#登录后台管理系统,输入 后台管理员 用户名 密码
firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
#点击客户管理-管理客户
DBshopEnterMenu2(firefox,'客户管理','管理客户')
#提取客户调整前的原始余额
num1=firefox.find_element_by_xpath('//td[contains(.,"%s")]/following-sibling::td[5]' % userName).text
# 1.点击“余额调整”按钮。
firefox.find_element_by_xpath\
    ('//td[contains(.,"%s")]/following-sibling::td[7]/a[2]' % userName).click()
time.sleep(3)
# 2.添加客户cyy,金额增加"10000",备注内容“买手机用”
firefox.find_element_by_xpath('//input[@id="money_change_num"]').send_keys(moneyChange)
time.sleep(2)
firefox.find_element_by_id('money_pay_info').send_keys(moneyPay)
# 3.点击“提交充值”按钮。
firefox.find_element_by_xpath('//button[text()="提交充值"]').click()
time.sleep(5)
#提取调整后的余额
num2=firefox.find_element_by_xpath('//td[contains(.,"%s")]/following-sibling::td[5]' % userName).text

# 登录前台管理系统,在前台 查询 cyy是否余额多10000.
firefox.get(url)
DBshopLogin(firefox, userName, password)
firefox.find_element_by_link_text('用户中心').click()
firefox.find_element_by_xpath('//a[text()="账户余额"]').click()
time.sleep(5)
#提取余额记录中，根据充值记录提取调整后的余额
num3=firefox.find_element_by_xpath\
            ('//td[contains(text(),"%s")]/following-sibling::td[text()="%s"]' % (moneyChange,num2)).text
num4=float(num3)-float(num1)

try:
    firefox.find_element_by_xpath\
            ('//td[contains(text(),"%s")]/following-sibling::td[text()="%s"]' % (num4,num3)).is_displayed()
    writeLog("%s 测试通过" % testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()


